<template>
    <!-- 过于拉跨已被弃用，留着警示自己的代码写的有多丑。 -->
    <div class="goods-card">
        <van-cell :title="goodsInfo.cusName" is-link />
        <div class="content">
            <div class="goods-info">
                <img src="../assets/images/logistics/order_pic.png" alt="" />
                <div class="txt-info">
                    <div>{{ goodsInfo.title }}</div>
                    <div><span>下单时间</span>{{ goodsInfo.orderTime }}</div>
                    <div><span>下单人</span>{{ goodsInfo.orderUserName }}</div>
                </div>
            </div>
            <van-button type="primary" class="sent" @click="toOderPage" v-if="goodsInfo.status === 0">发货</van-button>
            <van-button type="primary" class="get" @click="showPopup" v-if="goodsInfo.status === 10">收货</van-button>
            <van-button
                type="primary"
                class="evaluate"
                @click="
                    $router.push({
                        path: '/evaluation',
                        query: {
                            status: 'write',
                            serialNo: goodsInfo.serialNo,
                        },
                    })
                "
                v-if="goodsInfo.status === 20"
                >评价</van-button
            >
            <van-button
                type="primary"
                class="watch-evaluate"
                @click="
                    $router.push({
                        path: '/evaluation',
                        query: {
                            serialNo: goodsInfo.serialNo,
                        },
                    })
                "
                v-if="goodsInfo.status === 30"
                >查看评价</van-button
            >
        </div>
        <van-popup v-model="show" get-container="#app">
            <div class="tips">是否确认收货?</div>
            <div class="button-box">
                <div class="l" @click.stop="show = false">取消</div>
                <div class="r" @click.stop="confirmOder">确认收货</div>
            </div>
        </van-popup>
    </div>
</template>

<script>
import { ConfirmOderApi } from '@/request/api';

export default {
    props: ['goodsInfo'],
    data() {
        return {
            show: false,
        };
    },
    methods: {
        showPopup() {
            this.show = true;
        },
        toOderPage() {
            this.$router.push({
                path: '/shippingorderinfo',
                query: {
                    serialNo: this.goodsInfo.serialNo,
                },
            });
        },
        confirmOder() {
            ConfirmOderApi({
                serialNo: this.goodsInfo.serialNo,
            }).then(() => {
                this.show = false;
                this.$emit('refresh');
            });
        },
    },
};
</script>

<style lang="less" scoped>
.goods-card {
    background-color: #fff;
    color: #333;
    border-bottom: 0.01rem solid #e5e5e5;
    margin-bottom: 0.19rem;
    .van-cell {
        border-bottom: 0.01rem solid #e5e5e5;
        height: 1rem;
        align-items: center;
    }
    .content {
        padding: 0.33rem 0.28rem 0.25rem;
        overflow: hidden;
        .goods-info {
            display: flex;
            padding-bottom: 0.56rem;
            margin-bottom: 0.25rem;
            border-bottom: 0.01rem dashed #e5e5e5;
            img {
                width: 1.18rem;
                height: 1.18rem;
                margin-right: 0.3rem;
            }
            .txt-info {
                display: flex;
                flex-direction: column;
                justify-content: space-between;
                .title {
                    overflow: hidden;
                    text-overflow: ellipsis;
                    white-space: nowrap;
                    width: 5.4rem;
                }
                span {
                    color: #999;
                    margin-right: 0.24rem;
                }
            }
        }
        .van-button {
            float: right;
            min-width: 1.4rem;
            height: 0.6rem;
            box-sizing: border-box;
            border-radius: 0.6rem;
            &.sent {
                background-color: #003399;
                color: #fff;
                border: 0.01rem solid #003399;
            }
            &.get {
                background-color: #fff;
                color: #003399;
                border: 0.01rem solid #003399;
            }
            &.evaluate {
                background-color: #ffcc33;
                color: #fff;
                border: 0.01rem solid #ffcc33;
            }
            &.watch-evaluate {
                background-color: #fff;
                color: #ffcc33;
                border: 0.01rem solid #ffcc33;
            }
        }
    }
}
.van-popup--center {
    width: 5.2rem;
    height: 2.5rem;
    border-radius: 0.2rem;
    display: flex;
    flex-direction: column;
    color: #333;
    .tips {
        flex: 1;
        font-size: 0.3rem;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .button-box {
        border-top: 0.01rem solid #e5e5e5;
        height: 0.87rem;
        display: flex;
        position: relative;
        .l,
        .r {
            flex: 1;
            text-align: center;
            line-height: 0.87rem;
        }
        .l {
            color: #666;
        }
        .r {
            color: #4287ff;
        }
        &::after {
            content: '';
            position: absolute;
            height: 100%;
            width: 0.01rem;
            background-color: #e5e5e5;
            left: 50%;
            transform: translateX(-50%);
        }
    }
}
</style>
